<template>
	<view class="container">		
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption" :top="110">
			<view v-for="(item,index) in list " :key="index">
				<booking :itemDetail="item" :statusCode="statusCode" @Acceptance="TransferCar"/>				
			</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import booking from './bookingTemplate.vue'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import { queryAppointmentList,appointmentTransferCar } from '@/api/bookingManagement.js'
	export default {
		mixins: [MescrollMixin],
		components:{
			booking
		},
		props:{
			statusCode:{type:String,default:'1'},
			deliveryTime:{type:Number}
		},
		data(){
			return {
				list:[],
				upOption:{
					auto:false
				},
			}
		},
		watch:{
			statusCode(v){
				this.downCallback()
			}
		},
		methods:{
			downCallback(){
				this.list = []
				this.mescroll.resetUpScroll( true )
			},
			async upCallback(page){
				let pageObj = {
					pageIndex:page.num,
					pageSize:page.size,
					reserveStateCode:this.statusCode,
					deliveryTime:this.deliveryTime
				}				
				let res = await queryAppointmentList(pageObj)
				if(res.result === '1'){
					this.mescroll.endSuccess(res.rows.length)
					this.list = [...this.list,...res.rows]
					console.log('list',this.list)
				} else {
					this.mescroll.endErr()
				}			
			},
			TransferCar(v){
				const params = {
					reserveOrderId : v.reserveOrderId,
					cancelReason: v.cancelReason,
					updateControlId:v.updateControlId
				}
				console.log(v)
				appointmentTransferCar(params).then(res=>{
					console.log(res)
					uni.showToast({
						title:res.msg,
						icon:'none',						
					})
					this.downCallback()
				})
			}
		}
	}
</script>

<style>
</style>
